package DAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.swing.JOptionPane;

import GUI.Main;

public class ConnectionFactory
{
 String driverClassName="org.sqlite.JDBC";
 String connectionUrl="jdbc:sqlite:DB.db";
 String dbUser="root";
 String dbPwd="";
 
 private static ConnectionFactory connectionFactory=null;
 
 private ConnectionFactory()
 {
  try
  {
   Class.forName(driverClassName);
  }
  catch(ClassNotFoundException e)
  {
   		Main.showError("Errore:"+e.getMessage());
  }
 }
 
 public Connection getConnection() throws SQLException
 {
  Connection conn=null;
  conn=DriverManager.getConnection(connectionUrl,dbUser,dbPwd);
  return conn;
 }
 
 public static ConnectionFactory getInstance()
 {
  if(connectionFactory==null)
  {
   connectionFactory=new ConnectionFactory();
  }
  return connectionFactory;
 }
}